package com.taru.wxhsh.service.impl;

import com.taru.wxhsh.mapper.DetailMapper;
import com.taru.wxhsh.pojo.Detail;
import com.taru.wxhsh.service.DetailService;
import com.taru.wxhsh.util.UidGenerators;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.math.BigDecimal;
import java.util.List;

/**
 * Created by HuKang on 2018/5/30.
 */
@Service
public class DetailServiceImpl implements DetailService {
    @Autowired
    DetailMapper detailMapper;

    @Override
    public int insert(Detail detail) {
        detail.setDetailId(UidGenerators.getUuid());//设置主键
        //计算总价
        detail.setDetailTotalPrice(detail.getDetailProductPrice().multiply( new BigDecimal(detail.getDetailProductCount())));
        return detailMapper.insertSelective(detail);
    }

    @Override
    public List<Detail> qryCartList(String uid) {
        return detailMapper.qryCartList(uid);
    }

    @Override
    public int deleteByPrimaryKey(String detailId) {
        return detailMapper.deleteByPrimaryKey(detailId);
    }
}
